<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="java.util.*" pageEncoding="utf-8"%>
<%request.setCharacterEncoding("UTF-8");%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>POST提交数据</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"/>  
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="js/xmlhttp.js"></script>
</head>
<body>
 <form name="loginform" id="loginform">
        用户帐号:<input name="account" id="account" value="" size="15" maxlength="11"/><br /><br />
        登录密码:<textarea id="password1" name="password1">hello</textarea><br /><br />
        <input type="button" name="submit1" id="submit1" value="提交"/>
        <input type="reset" name="reset1" id="reset1" value="重置" />
    </form>
<div id="msgdata"></div>
<script>
$(function(){
	XMLHttp.sendRequest("GET", "t.jsp", "",call1);
	function call1(obj){
		$('#msgdata').html(obj.responseText);
	}
	
 $("#submit1").click(function(){
	 helloWorld();
 });
  
 function analyseForm(form) // 分析form的元素
 {
  var params = new Array();
  for(var i = 0; i < form.elements.length; i++)
  {
     var param = form.elements[i].name;
     param += "=";
     param += form.elements[i].value;
     params.push(param);
  }
  return params.join("&");//返回的是一个数组
 }
 
 function helloWorld()//ajax提交函数
 {
  var form = document.getElementById("loginform");
  var formBody =analyseForm(form);//准备好要提交的值
  url='test2.jsp';//服务器处理数据的地址
  XMLHttp.sendRequest('POST',url,formBody,getHello);
 }
 
 function getHello()//处理ajax返回信息的函数
 {
    alert("hello");
  }
	
	
});

</script>
</body>
</html>